<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">发ajax请求</button>
    <script>
        document.querySelector('#btn').onclick = () => {
                const xhr = new XMLHttpRequest();
                xhr.open("GET", 'http://localhost:8081/origin-server');
                xhr.send();
                xhr.onreadystatechange = () => {
                    //为4时代表响应数据代表全部接受完成
                    if (xhr.readyState === 4) {
                        if (xhr.status >= 200 && xhr.status < 300) {
                            alert('请求成功:' + xhr.responseText);
                        } else {
                            alert('请求失败 status=' + xhr.status)
                        }
                    }
                }
            }
    </script>
</body>

</html>